package com.knowif.backend.controller;

import com.knowif.backend.service.StanderSorceService;
import com.knowif.pojo.StanderSorce;
import com.knowif.service.StanderSorce_service;
import com.knowif.system.model.RestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat")
public class StanderSorceController {
    @Autowired
    private StanderSorceService standerSorceService;

    /**
     * 保存前删除面经，面经只保留一份
     * @param standerSorce
     * @return
     */
    @PostMapping("/standerSorce/save")
    @Transactional
    @ResponseBody
    public RestBean standerSorceDelBeforeSave(@RequestBody StanderSorce standerSorce){
        standerSorceService.standerSorceDelBeforeSave(standerSorce);
        return RestBean.buildSuccess("修改标准化成绩成功");
    }

    /**
     * 根据用户查询分数
     * @param userId
     * @return
     */
    @GetMapping("standerSorce/query")
    @ResponseBody
    public RestBean standerSorceQuery(Integer userId){
        List<StanderSorce> standerSorces = standerSorceService.standerSorceQuery(userId);
        return RestBean.buildSuccess(standerSorces);
    }

    /**
     * 查询数据库的内容部分更新
     * @param standerSorce
     * @return
     */
    @PostMapping("/standerSorce/update")
    @Transactional
    @ResponseBody
    public RestBean updateFromDB(@RequestBody StanderSorce standerSorce){
        boolean flag = standerSorceService.updateFromDB(standerSorce);
        if(!flag){
            RestBean.buildError("修改失败！");
        }
        return RestBean.buildSuccess("修改成功！");
    }
}
